package com.example.ass.service.impl;

import com.example.ass.mapper.StudentMapper;
import com.example.ass.pojo.Student;
import com.example.ass.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Student findByStudentName(String name) {
        return studentMapper.findByStudentName(name);
    }

    @Override
    public void register(String username, String password) {
        Student student = new Student();
        student.setName(username);
        student.setPassword(password);
        studentMapper.insertStudent(student);
    }

    @Override
    public Student login(String username, String password) {
        Student student = studentMapper.findByStudentName(username);
        if (student != null && student.getPassword().equals(password)) {
            return student; // 登录成功，返回学生对象
        }
        return null; // 登录失败，返回 null
    }
}